/*
 * @FilePath: index.ts
 * @Author: liuqiong
 * @Date: 2023-09-20 14:18:51
 * @LastEditors: liuqiong
 * @LastEditTime: 2023-11-09 17:14:45
 * @Description: 公用的工具类
 */
/**
 * 获取随机数
 *
 * @export
 * @param {number} minNum
 * @param {number} maxNum
 * @returns
 */
export function randomNum(minNum: number, maxNum: number) {
  switch (arguments.length) {
    case 1:
      return parseInt(Math.random() * minNum + 1 + "", 10);
    case 2:
      return parseInt(Math.random() * (maxNum - minNum + 1) + minNum + "", 10);
    default:
      return 0;
  }
}


const baseURL = import.meta.env.VITE_BASE_URL
const projectName = baseURL.slice(1) + '_'

export function getItem(key: string) {
  return localStorage.getItem(projectName + key)
}

export function setItem(key: string, value: string) {
  return localStorage.setItem(projectName + key, value)
}

export function removeItem(key: string) {
  return localStorage.removeItem(projectName + key)
}

// 递归实现深拷贝
export const deepCopy = (obj: { [x: string]: any }) => {
  const objCopy: any = Array.isArray(obj) ? [] : {}
  if (obj && typeof obj === 'object') {
    for (const key in obj) {
      if (obj[key] && typeof obj[key] === 'object') {
        objCopy[key] = deepCopy(obj[key])
      } else {
        objCopy[key] = obj[key]
      }
    }
  }
  return objCopy
}